package com.ywgt.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywgt.system.pojo.Log;
import com.ywgt.system.mapper.LogMapper;
import com.ywgt.system.service.LogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 操作日志表 服务实现类
 * </p>
 *
 * @author yiping
 * @since 2021-01-22
 */
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, Log> implements LogService {

    @Autowired
    private LogMapper logMapper;

    @Override
    public Page<Log> findLogList(Long pageNum, Long pageSize, Log log) {
        Page<Log> logPage=new Page<>(pageNum,pageSize);
        return logMapper.selectPage(logPage,getWrapper(log));
    }



    public LambdaQueryWrapper<Log> getWrapper(Log log){
        LambdaQueryWrapper<Log> queryWrapper=new LambdaQueryWrapper<>();
        if (log!=null) {
            if (!StringUtils.isEmpty(log.getLocation())) {
                queryWrapper.eq(Log::getLocation, log.getLocation());
            }
            if (!StringUtils.isEmpty(log.getId())) {
                queryWrapper.eq(Log::getIp, log.getIp());
            }
            if (!StringUtils.isEmpty(log.getUsername())) {
                queryWrapper.like(Log::getUsername, log.getUsername());
            }
        }
        return queryWrapper;
    }
}
